std::ratio
From Cppreference
| C++ Standard Library | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | |||||||||||||||||||||||||||||||||||||||||||
| Compile time rational arithmetic | |||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||
| Defined in header <ratio>
|
||
| template< intmax_t Num, intmax_t Denom = 1 >
class ratio { |
(C++11 feature) | |
The class template ratio is the core class in the compile-time rational arithmetic library. It reduces the supplied numerator and denominator to the lowest terms.
Several convenience SI typedefs are already provided:
| typedef std::ratio<1, 1000000000000000000000000> yocto; //see below
typedef std::ratio<1, 1000000000000000000000> zepto; //see below |
(C++11 feature) | |
The typedefs yocto, zepto, zetta, yotta are provided only if intmax_t is sufficient to represent the values used to instantiate the templates.
[edit] Template parameters
| Nom | - | defines the numerator of the ratio |
| Denom | - | defines the denominator of the ratio. It cannot be equal to 0 |
[edit] Member objects
| num | defines the reduced numerator (public static member constant) |
| den | defines the reduced denominator (public static member constant) |